package edu.ncst.baseweb.controller.webmanage;

import cn.wintersun.basecommon.common.Result;
import edu.ncst.baseweb.dao.web.LabDownload;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/lab/download")
@PreAuthorize("hasAuthority('6')")
public class LabDownloadManageController {

    @Autowired
    private edu.ncst.baseweb.service.intrer.webmanage.LabDownloadManageService LabDownloadManageService;

    @RequestMapping(value = "list",method = RequestMethod.POST)
    public Result<IPage<LabDownload>> list(@RequestBody LabDownload LabDownload){

        return  LabDownloadManageService.list(LabDownload);
    }

    @RequestMapping(value = "save",method = RequestMethod.POST)
    public Result<Object> save(@RequestBody LabDownload LabDownload){

        return  LabDownloadManageService.save(LabDownload);
    }

    @RequestMapping(value = "delete",method = RequestMethod.POST)
    public Result<Object> delete(@RequestBody String LabDownloadId){
        try {
            return LabDownloadManageService.delete(LabDownloadId);
        } catch (Exception e) {
            return Result.failure(500, e.getMessage());
        }
    }
    @PostMapping("/upload")
    public String uploadFile(@RequestParam("image") MultipartFile file, @RequestParam("id") Integer id) {

        // 处理图片上传逻辑
        if (!file.isEmpty()) {
            return LabDownloadManageService.uploadFile(file,id);
        } else {
            return "请选择要上传的图片";
        }
    }

}